package com.yuan.springcloud.consumer;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * Rabbit消息监听处理
 * autoDelete：队列的持久性
 *   - 设置为false代表持久化，数据会保存到硬盘
 *   - 设置为true代表不持久化，数据放在内存，如果rabbitmq报错，就会出现消息丢失
 * @author YouYuan
 * @date 2020/4/7 17:31
 */
@Component
@RabbitListener(bindings = @QueueBinding(
        value = @Queue(value = "${amqp.queue.email}", autoDelete = "false"),
        exchange = @Exchange(value = "${amqp.exchange.direct}", type = ExchangeTypes.DIRECT),
        key = "email"
))
public class RabbitEmailMessageListener {

    @Value("${amqp.exchange.fanout}")
    private String exchange;
    @Value("${amqp.queue.email}")
    private String queue;

    @RabbitHandler
    public void msgHandler(String message) {
        System.out.println("email: " + exchange + "-" + queue + ":" + message);
    }
}
